% view_acpc.m - view an afni acpc mri in BRIK coordinates
%

%function [Ds] = view_acpc (brick_file)
function view_acpc(vol, thresh)

global title_str scalp hiso

% fprintf('\nImaging ....');
% fprintf('\nEstimated Time: 0.6 minutes\n');
% tic;
% Replacing mask and vol RAI coords into coords displayed as RAI coords on
% rendered image. quirky matlab imaging thing.
%  Order is RAI. Right side of face has pos numbers. Matlab display
%  problem']);
%

vol = permute(vol,[2 1 3]);

%Ds = vol;

% smooth the volume for a clearer display
% vol is frequently the vol_mask input so not smoothed
%
% [x,y,z,vol] = reducevolume(vol,[2,2,2]); % spedup but holey :(
Ds = smooth3(vol); 
clear data x y z vol;

% ,thresh
scalp=isosurface(Ds);
hiso = patch(isosurface(Ds),...
    'FaceColor',[1,0.75,0.65],...
    'EdgeColor','none');
% reducepatch(hiso,0.99);
isonormals(Ds,hiso);
% keyboard

view(-45,30) 
daspect([1,1,1])

% h = camlight('left');
% for i = 1:10;
%     camorbit(360/9,0)
%     camlight(h,'left')
%     drawnow;
% end
% 
%camlight(-45,30);

lightangle(-60,30); 
%camlight(-60,30); 
lightangle(+60,30);
lightangle(+180,30);

set(gcf,'Renderer','zbuffer'); lighting phong
%set(hcap,'AmbientStrength',0.6); 
% isonormals(Ds,hiso)
% set(hiso,'SpecularColorReflectance',0,'SpecularExponent',50,...
%     'SpecularStrength',0.25,'AmbientStrength',0.1,'DiffuseStrength',.7)
%
% material([ka kd ks])  sets the ambient/diffuse/specular strength of the
% objects.
% material dull;
material([.5 .4 .05])

rotate3d on;
xlabel('X');
ylabel('Y');
zlabel('Z');
if isempty(title_str)
    title(['Threshold = ',num2str(thresh),'']); 
else
    title(title_str)
end
axis off
axis tight
% fprintf('Actual Time: %-2.1f minutes\n', toc/60);
clear Ds;
